import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/tour_user";

export const geo_api = (
  data: { lng: number; lat: number },
  showError = true
) => {
  return Http.get<{ city_id: string; city_name: string; in_china: 1 }>(
    `/v1${baseUrl}/geo`,
    data
  ).catch(error => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const get_geo_api = (showError = true) => {
  return Http.get<any>(`${baseUrl}/get_geo`).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};
